<?
	@session_start();
	
	function CheckPermission()
	{
		if(!isset($_SESSION["canAccess"]) || $_SESSION["canAccess"] != 'true')
		{
			echo '<script type="text/javascript"> window.location="login.php"; </script>';
		}
	}
	
	function CheckCanCreate()
	{
		if((Session('accessType') & 2) == '0')
		{
			echo '<script type="text/javascript"> window.location="search.php"; </script>';
		}
	}
	
	function Session($name)
	{
		return $_SESSION[$name];
	}
	
	//accessType & 1 == true ~ myself
	//accessType & 2 == true ~ can edit others
	//accessType & 4 == true ~ see all info
	//profileId;
	function IsMyself()
	{
		$id = $_GET['profileId'];
		if(Session('accessType') & 2 != 0)
			return true;
		else if(Session('accessType') & 1 != 0 && Session('profileId') == $id)
			return true;
		else
			return false;
	}
	
	function CanSeeAllInfo()
	{
		return (Session('accessType') & 4 != 0);
	}
	
	function DestroyPermission()
	{
		@session_destroy();
	}

	function GetName($fullName)
	{
		$nameTokens = TokenString($fullName);
		return trim($nameTokens[0]);
	}
	
	function GetLastName($fullName)
	{
		$tokens = TokenString($fullName);
		$rs = "";
		for($i=1;$i<count($tokens);$i++)
			$rs = $rs . $tokens[$i] . " ";
		return trim($rs);
	}

	function TokenString($string)
	{
		$tokens = split(' ', $string);
		return $tokens;
	}
?>